/* socket.h : dgnsc socket
 * Copyright (C) 2009-2010 drangon <drangon.zhou@gmail.com>
 * 2009-05
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */

#ifndef INCLUDED_DGNSC_SOCKET_H
#define INCLUDED_DGNSC_SOCKET_H

#ifdef __cplusplus
extern "C" {
#endif // __cplusplus

typedef void * dgn_sock_t;

int dgn_sock_host_to_ip( const char * host, char ip[32] ); // host can = ip

dgn_sock_t dgn_sock_tcp_svr( const char * listen_host, int port );
dgn_sock_t dgn_sock_tcp_connect( const char * remote_host, int port, int timeout_ms );
dgn_sock_t dgn_sock_accept( dgn_sock_t listen_sock, int timeout_ms );
dgn_sock_t dgn_sock_udp( const char * bind_host, int port );

int dgn_sock_local_addr( dgn_sock_t sock, char ip[32], int * port );
int dgn_sock_remote_addr( dgn_sock_t sock, char ip[32], int * port );

int dgn_sock_send( dgn_sock_t sock, const char * buf, int len, int timeout_ms );
int dgn_sock_recv( dgn_sock_t sock, char * buf, int minlen, int maxlen, int timeout_ms );

int dgn_sock_sendto( dgn_sock_t sock, const char * buf, int len, const char * remote_host, int port );
int dgn_sock_recvfrom( dgn_sock_t sock, char * buf, int len, char remote_ip[32], int * port, int timeout_ms );

void dgn_sock_close( dgn_sock_t sock );

#ifdef __cplusplus
}
#endif // __cplusplus

#endif // INCLUDED_DGNSC_SOCKET_H

